﻿Module Entrada_Datos
    Sub Formatea_Numeros(ByVal textbox As TextBox, ByVal Tipo As Integer)
        If Tipo = 2 Then
            Dim Valor As Double = textbox.Text
            textbox.Text = Format(Valor, "###,###,##0.#0")
        ElseIf Tipo = 0 Then
            Dim Valor As Double = textbox.Text
            textbox.Text = Format(Valor, "N0")
        End If

    End Sub
    Sub Aplica_Config_Numeros(ByVal textbox As TextBox, ByVal SEPARADOR As Char)
        Dim DT As String
        'Para adaptar a la configuracion del PC huesped.
        DT = Replace(textbox.Text, ".", SEPARADOR)
        DT = Replace(DT, ",", SEPARADOR)
        'Label1.Text = CDbl(DT)
        On Error Resume Next
        textbox.SelectionStart = 0
        textbox.SelectionLength = Len(textbox.Text)
        'Data.Focus()
    End Sub
    Sub Valida_Formato_Numeros(ByVal textbox As TextBox, ByVal SEPARADOR As Char)
        If textbox.Text = SEPARADOR Then
            'si el separador decimal es tecleado directamente
            textbox.Text = "0" & SEPARADOR
            textbox.SelectionStart = Len(textbox.Text)
        ElseIf Not IsNumeric(Trim(textbox.Text)) Then
            Beep()
            If Len(textbox.Text) < 1 Then
                textbox.Text = "0"
            Else
                textbox.Text = Microsoft.VisualBasic.Left(textbox.Text, Len(textbox.Text) - 1)
                textbox.SelectionStart = Len(textbox.Text)
            End If
        End If
    End Sub
    Sub Formato_Titulo(ByVal TextBox As TextBox)
        Dim texto As String = TextBox.Text
        If texto = "" Then
            Exit Sub
        End If
        Dim longtext As Integer = Len(texto)
        Dim caracter As String = Mid(texto, longtext, 1)
        Dim anterior As String = Mid(texto, 1, longtext - 1)

        If longtext = 1 Then
            TextBox.Text = UCase(caracter)
        Else
            Dim Titulo As String = anterior & UCase(caracter)
            TextBox.Text = FORMAT_CULTURA.ToTitleCase(Titulo)
        End If
        TextBox.Select(longtext + 1, longtext + 1)
    End Sub
End Module
